'use strict';

const Controller = require('egg').Controller;
let fruitsList = [{
    id: "1",
    name: "小明",
  },
  {
    id: "2",
    name: "小红",
  },
  {
    id: "3",
    name: "小绿",
  },
  {
    id: "4",
    name: "王小虎",
  },
]
class FruitsController extends Controller {
  // /fruits get请求
  async index() {
    this.ctx.body = fruitsList;
  }
  // post请求
  async create() {
    const fruit = this.ctx.request.body.fruit
    fruitsList.push(fruit)
    this.ctx.body = "添加成功"
  }
  // /fruit/:id   delete请求
  async destroy() {
    let id = this.ctx.params.id;
    fruitsList.splice(id, 1)
    this.ctx.body = "删除成功"
  }
}

module.exports = FruitsController;